<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- Bootstrap CSS-->
		<link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css">
		<!-- Font Awesome CSS-->
		<link rel="stylesheet" href="../vendor/font-awesome/css/font-awesome.min.css">
		<!-- Custom Font Icons CSS-->
		<link rel="stylesheet" href="../css/font.css">
		<!-- theme stylesheet-->
		<link rel="stylesheet" href="../css/style.default.css" id="theme-stylesheet">
		<!-- Custom stylesheet - for your changes-->
		<link rel="stylesheet" href="../css/custom.css">
		<link rel="stylesheet" href="../css/layer.css">
		<link rel="stylesheet" href="../bootstrap/css/bootstrap-switch.min.css">
		<link rel="stylesheet" href="../css/layer.css">
		<script src="../vendor/jquery/jquery.min.js"></script>
		<title>查看用户</title>
	</head>
	<body>
		<div>
			<header class="header">
				<nav class="navbar navbar-expand-lg">
					<div class="search-panel">
						<div class="search-inner d-flex align-items-center justify-content-center">
							<div class="close-btn">Close <i class="fa fa-close"></i></div>
							<form id="searchForm" action="#">
								<div class="form-group">
									<input type="search" name="search" placeholder="What are you searching for...">
									<button type="submit" class="submit">Search</button>
								</div>
							</form>
						</div>
					</div>
					<div class="container-fluid d-flex align-items-center justify-content-between">
						<div class="navbar-header">
							<!-- Navbar Header-->
							<a href="home.html" class="navbar-brand">
								<div class="brand-text brand-big visible text-uppercase"><strong class="text-primary">小标</strong><strong>会议平台</strong></div>
								<div class="brand-text brand-sm"><strong class="text-primary">X</strong><strong>B</strong></div>
							</a>
							<!-- Sidebar Toggle Btn-->
							<button class="sidebar-toggle"><i class="fa fa-long-arrow-left"></i></button>
						</div>
						<div class="right-menu list-inline no-margin-bottom">
							<!-- Log out -->
							<div class="list-inline-item logout">
								<a id="logout" href="../index.html" class="nav-link"><span class="d-none d-sm-inline">Logout </span></a>
							</div>
						</div>
					</div>
				</nav>
			</header>
			<div class="d-flex align-items-stretch" id="app">
				<!-- Sidebar Navigation-->
				<nav id="sidebar">
					<!-- Sidebar Header-->
					<div class="sidebar-header d-flex align-items-center">
						<div id="avatar" class="avatar"><img :src="loginUserInfo.pic" alt="..." class="img-fluid rounded-circle"></div>
						<div class="title">
							<h1 class="h5">{{loginUserInfo.realName}}</h1>
							<p>{{loginUserInfo.deptName}}</p>
						</div>
					</div>
					<!-- Sidebar Navidation Menus-->
					<span class="heading">Main</span>
					<ul class="list-unstyled">
						<li><a href="home.html"> <i class="icon-home"></i>主页 </a></li>
						<li><a href="#userDropdown" data-toggle="collapse" aria-expanded="true"> <i class="icon-windows"></i>用户列表</a>
							<ul id="userDropdown" class="collapse show">
								<li class="active"><a href="user.html">查看用户</a></li>
								<li><a href="my_user.html">我关注的用户</a></li>
								<li><a href="article.html">发布文章</a></li>
								<li><a href="article_collect.html">我的收藏</a></li>
							</ul>
						</li>
						<!--<li><a href="login.html"> <i class="icon-logout"></i>Login page </a></li>-->
						<li>
							<a href="#depDropdown" data-toggle="collapse"> <i class="icon-windows2"></i>部门列表</a>
							<ul id="depDropdown" class="collapse list-unstyled ">
								<li><a href="department.html">全部部门</a></li>
								<li><a href="meeting.html">会议系统</a></li>
							</ul>
						</li>
					</ul>
				</nav>
				<!-- Sidebar Navigation end-->
				<div class="page-content">
					<div class="page-header">
						<div class="container-fluid">
							<h2 class="h5 no-margin-bottom">用户列表</h2>
						</div>
					</div>
					<section class="no-padding-bottom">
						<div class="title">
							<div class="form-inline">
								<div class="form-group">
									<label for="inlineFormInput" class="sr-only">Name</label>
									<input id="inlineFormInput" v-model="searchName" type="text" placeholder="请输入用户名..." class="mr-sm-3 form-control">
								</div>
								<div class="form-group">
									<input type="button" @click="search(1)" value="查询" class="btn btn-primary">
								</div>
							</div>
						</div>
						<div class="table-responsive">
							<table class="table">
								<thead>
									<tr>
										<th>ID</th>
										<th>用户名</th>
										<th>姓名</th>
										<th>性别</th>
										<th>年龄</th>
										<th>简介</th>
										<th>操作</th>
										<th>加关注</th>
									</tr>
								</thead>

								<tbody v-if="showList">
									<div style="width: 100%;">
										<tr v-for="u in userList.content">
											<th scope="row">{{u.id}}</th>
											<td>{{u.username}}</td>
											<td>{{u.realName}}</td>
											<td>{{u.age}}</td>
											<td>{{u.gender==1?'女':u.gender==0?'男':''}}</td>
											<td>{{u.desc}}</td>
											<td><button v-if="u.username!=loginUserInfo.username" @click="userDetail(u.id)" class="btn-xs btn-primary userDetail">详细信息</button></td>
											<td><input v-if="u.username!=loginUserInfo.username" @change="changeFocus(u.id, u.focus)" type="checkbox"
												 v-model="u.focus" value="true" class="checkbox-template"></td>
										</tr>
									</div>
								</tbody>
								<nav class="text-center" aria-label="Page navigation">
									<ul class="pagination">
										<li>
											<a href="#" @click="search(currPage-1)" aria-label="Previous">
												<span aria-hidden="true">&laquo;</span>
											</a>
										</li>
										<li v-for="num in userList.totalPages"><a href="#" @click="search(num)">{{num}}</a></li>
										<li>
											<a href="#" @click="search(currPage+1)" aria-label="Next">
												<span aria-hidden="true">&raquo;</span>
											</a>
										</li>
									</ul>
								</nav>

							</table>
						</div>
					</section>

					<footer class="footer">
						<div class="footer__block block no-margin-bottom">
							<div class="container-fluid text-center">
								<p class="no-margin-bottom">Copyright &copy; 2019.Company <a href="#">东方标准</a></p>
							</div>
						</div>
					</footer>
				</div>
			</div>
		</div>
		<!-- JavaScript files-->
		<script src="../vendor/popper.js/umd/popper.min.js"></script>
		<script src="../vendor/bootstrap/js/bootstrap.min.js"></script>
		<script src="../bootstrap/js/bootstrap-switch.min.js"></script>
		<script src="../vendor/jquery.cookie/jquery.cookie.js"></script>
		<script src="../vendor/chart.js/Chart.min.js"></script>
		<script src="../js/layer.js"></script>
		<script src="../vendor/jquery-validation/jquery.validate.min.js"></script>
		<!-- <script src="../js/charts-home.js"></script> -->
		<script src="../js/front.js"></script>
		<script src="../js/custom.js"></script>
		<script src="../js/vue-2.6.11.js"></script>
		<script src="../js/axios-0.19.2.min.js"></script>
		<script src="../js/jquery-cookie-1.4.1.js"></script>
		<script type="text/javascript">
			let vm = new Vue({
				el: '#app',
				data: {
					loginUserInfo: {},
					currPage: 1,
					searchName: "",
					userList: '',
					showList: true
				},
				methods: {
					search(page) {
						this.currPage = page;
						axios({
							url: '/user/search',
							params: {
								page: page,
								search: this.searchName.trim()
							}
						}).then((response) => {
							this.userList = response.data.obj;
							if (this.userList != null) this.showList = true;
							// console.log(response.data.obj);
						})
					},
					userDetail(uid) {
						axios({
							url: `/user/detail/${uid}`
						}).then((response) => {
							if (response.data.flag) {
								layer.msg("对方设置了私密");
							} else {
								sessionStorage.setItem("userId", uid);
								location.href = "/html/user_detail.html";
							}
						})
					},
					changeFocus(uid, ufocus) {
						axios({
							url: '/user/updateFocus',
							params: {
								id: uid,
								state: ufocus
							}
						}).then((response) => {
							layer.msg(response.data.obj);
						})
					}
				},
				created: function() {
					this.loginUserInfo = JSON.parse(sessionStorage.getItem("loginUser"));
				},
				mounted: function() {
					this.search(1);
				}
			})
		</script>
	</body>
</html>
